﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class AdminControl_EmployeesDetails : System.Web.UI.UserControl
{
    DataTable dataTable = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadDataForGrid();
        }
       
    }

    private void loadDataForGrid()
    {
        dataTable = new DataTable();
        dataTable.Columns.Add("staffname");
        dataTable.Columns.Add("username");
        dataTable.Columns.Add("position");
        dataTable.Columns.Add("phone");
        dataTable.Columns.Add("address");
        dataTable.Columns.Add("salary");
        dataTable.Columns.Add("joindate");
        dataTable.Columns.Add("edit");
        dataTable.Columns.Add("delete");
        dataTable.Columns.Add("staffID");

        ShoppingDataContext spdt = new ShoppingDataContext();
        var emps = from p in spdt.STAFFs
                   select p;

        foreach (var emp in emps)
        {
            DataRow row = dataTable.NewRow();
            row["staffname"] = emp.Fullname;
            row["username"] = emp.username;
            row["position"] = emp.position;
            row["phone"] = emp.phone;
            row["address"] = emp.address;
            row["salary"] = emp.salary;
            row["joindate"] = emp.joindate;
            row["edit"] = "EditEmployee.aspx?employeeid=" + emp.StaffID;
            row["delete"] = "DeleteEmployee.aspx?employeeid=" + emp.StaffID;
            row["staffID"] = emp.StaffID;
            dataTable.Rows.Add(row);
        }

        employeesdetails.DataSource = dataTable;
        employeesdetails.DataBind();
    }
    protected void employeesdetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {

    }
    protected void employeesdetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        HiddenField hddStaffID=(HiddenField)employeesdetails.Rows[e.RowIndex].FindControl("HiddenField1");
        string staffId = hddStaffID.Value;
    }
}
